﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;

namespace KPIS.GERP.GHRMS.DAL
{
    public sealed class TrainingDAL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public TrainingDAL()
        {

        }
        public DataSet LoadTrainingHistories(Nullable<int> EmpSequence)
        {
            string strSQL;

            DataSet ds = null;

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@ActiveRecord", SystemInfo._ActiveRecordStatus);
                dbManager.AddParameters(1, "@EmpSequence", EmpSequence);

                strSQL = "SELECT tn.TRAINEE_SEQ, tn.EMP_SEQ, c.SCHEDULE_TEXT"
                        + ", c.TRAINING_COURSE_DESCR, c.DATE_TRAINING_START, c.DATE_TRAINING_END"
                    + " FROM HRM_TRAINING_COURSES_TRAINEES tn"
                        + " LEFT JOIN HRM_TRAINING_COURSES c ON tn.TRAIN_SEQ = c.TRAIN_SEQ"
                    + " WHERE tn.RECORD_STATUS = @ActiveRecord"
                        + " AND tn.GRANTED = 1"
                        + " AND c.CLOSED = 1"
                    + (EmpSequence.HasValue ? " AND tn.EMP_SEQ = @EmpSequence" : "");
                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);
                
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.CloseReader();
                dbManager.Dispose();
            }
            return ds;
        }
    }
}
